#ifndef _UPLOAD_LINK_MANAGER_H_
#define _UPLOAD_LINK_MANAGER_H_
#include <QThread>
#include "event.h"
#include "link_manager.h"

class QThread;
class QTcpSocket;
class UploadLinkManager: public BaseLinkManager
{
	Q_OBJECT
	typedef void (UploadLinkManager::*net_handler_t)(void *buffer);
public:
	UploadLinkManager(int socketDescriptor, QObject *parent = 0);
	~UploadLinkManager();
	void stop();
	void cleanUp() {}
protected:
	void run();
	void onRequestDownloadUrl(void *buffer);
	void onRequestFileInfo(void *buffer);
	void onRequestDownloadSection(void *buffer);
protected slots:
	void onReadSocket();
	void onReadFile(quint64 requestId, int pieceIndex, qint64 offset, 
			const QByteArray& data);
	void onDisconnect();
private:
	typedef QMap<int, net_handler_t> NetHandlerMap;
	int socketDescriptor;
	NetHandlerMap netHandlers;
	quint64 requestId;
	QTcpSocket *socket;
	FileManager *fileManager;
	quint16 buf_size;
	char buffer[MAX_EVENT_LENGTH];
};

#endif // _UPLOAD_LINK_MANAGER_H_
